#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "str.h"

#if 0
int main(void)
{
	String string, sub;

	InitString(string);
	StrAssign(string, "abcdefghijkl");
	InitString(sub);

	SubString(string, sub, 4, 3);
	printf("%s\n", sub);

	StrInsert(string, 1, sub);
	printf("%s\n", string);

	StrDelete(string, 1, 3);
	printf("%s\n", string);

	return 0;
}
#endif

#if 0
int main(void)
{
	String string, T, Y;

	InitString(string);
	char *str = "abcdef";
	StrAssign(string, str);
	printf("%s\n", string);

	InitString(T);
	StrCopy(T, string);
	printf("%s\n", T);
	int len = StrLength(T);
	printf("len = %d\n", len);

	StrAssign(T, "abc");
	printf("%s\n", T);

	int res = StrCompare(string, T);
	printf("result = %d\n", res);

	InitString(Y);
	StrConcat(Y, string, T);
	printf("%s\n", Y);

	return 0;
}
#endif

#if 1
int main(void)
{
	String S, T, Z;

	InitString(S);
	StrAssign(S, "ababcabcacbab");
	InitString(T);
	StrAssign(T, "cbc");

	// int index = StringIndex(S, T, 0);
	int index = KMP(S, T, 0);
	switch (index)
	{
	case -1:
		fprintf(stderr, "argument pos illegal\n");
		break;
	case -2:
		fprintf(stderr, "empty string\n");
		break;
	case -3:
		fprintf(stderr, "malloc() failed\n");
		break;
	case -4:
		printf("can not find \"%s\" in \"%s\" \n", T, S);
		break;
	default:
		printf("index = %d\n", index);
		break;
	}

	// InitString(Z);
	// StrAssign(Z, "xy");
	// printf("%s\n", S);

	// StrReplace(S, T, Z);
	// printf("%s\n", S);

	return 0;
}
#endif
